<template>
	<view class="container">
		<view class="formBox">
			<uni-forms ref="form" :modelValue="FormData" :rules="rules">
				<view class="box">
					<uni-forms-item label="费用类型">
						<uni-data-checkbox v-model="FormData.bill_type" :localdata="billType"></uni-data-checkbox>
					</uni-forms-item>
					<uni-forms-item required label="费用名称" name="bill_title">
						<uni-easyinput type="text" v-model="FormData.bill_title" :clearable="false" placeholder="请输入费用名称" />
					</uni-forms-item>
					<uni-forms-item required label="记账金额" name="bill_money">
						<uni-easyinput type="digit" v-model="FormData.bill_money" :clearable="false" placeholder="请输入记账金额" />
					</uni-forms-item>
					<uni-forms-item required label="日期"  name="bill_date">
						<picker mode="date" @change="bindDate" :value="FormData.bill_date">
							<view class="picker-input">
								{{ FormData.bill_date }}
								<uni-icons type="right" size="16" color="#bbb"></uni-icons>
							</view>
						</picker>
					</uni-forms-item>
				</view>
				<view class="btns">
					<button class="btn" type="primary" @click="submit">确 定</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			FormData: {
				bill_title: '',
				bill_money: '',
				bill_date: '',
				bill_type: 'income',
				is_pay: 1
			},
			rules: {
				bill_title: {
					rules: [
						{
							required: true,
							errorMessage: '请填写费用名称'
						}
					]
				},
				bill_money: {
					rules: [
						{
							required: true,
							errorMessage: '请填写记账金额'
						}
					]
				},
				bill_date: {
					rules: [
						{
							required: true,
							errorMessage: '请选择日期'
						}
					]
				}
			},
			billType: [
				{
					text: '收入',
					value: 'income'
				},
				{
					text: '支出',
					value: 'payed'
				}
			]
		};
	},
	methods: {
		bindDate(e) {
			this.FormData.bill_date = e.detail.value;
		},
		submit() {
			this.$refs.form.validate().then((res) => {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				let object = this.FormData;
				prevPage.$vm.billPayUpdate(object);
				uni.navigateBack();
			});
		}
	}
};
</script>